<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/4
 * Time: 13:49
 */
header('Content-type:text/html;charset=utf-8');

$lian = mysql_connect('localhost','root','root');

if(!$lian){
	die('连接数据库失败'.mysql_error());
}




mysql_query('set name utf8');
mysql_query('use `db`');






$where ='';

if(isset($_GET['keyword'])){

	$keyword=$_GET['keyword'];
	$keyword = mysql_real_escape_string($keyword);
	$where = "where e_name like '%$keyword%'";

}



$fields = array('e_dept','date_of_entry','e_id');

//初始化排序语句，用来组合排序的order子句
$sql_order='';
//判断&_GET['order']是否存在，如果存在则将其赋值给$order;如果不存在，则赋值$order
$order = isset($_GET['order']) ? $_GET['order']:'';
$sort = isset($_GET['sort']) ? $_GET['sort']:'';
//判断$order是否存在于合法字段列表$fields中
if(in_array($order,$fields)){
	if($sort =='desc'){
		$sql_order="order by $order desc";
		$sort='asc';
	}else{
		$sql_order="order by $order asc";
		$sort='desc';
	}

}


$sql="select * from `emp_info` $sql_order $where";

$result = mysql_query($sql,$lian);
//遍历数`
$emp_info=array();
while($row = mysql_fetch_assoc($result)){

	$emp_info[]=$row;
};

require 'list_html.php';





